function X_cont_ix = fn_cont_ix(tr_alpha,tr_beta,Xret,deltan,nDays,nObs_per_day)
% IN
%      tr_alpha         jump truncation para
%      tr_beta
%      Xret             size [p, n], and this allows for p>1
%      deltan
%      nDays            number of DAYS, cannot be other time intervals.
%      nObs_per_day
% OUT
%      X_cont_ix        logicals: is Xret cont? size [p n]

if isvector(Xret)
  X_cont_ix = fn_jump_ix_1variable(tr_alpha,tr_beta,Xret,deltan,nDays,nObs_per_day);
else
  X_cont_ix = -999*ones(size(Xret));
  p         = size(Xret,1);
  for idx_p = 1:p
    X_cont_ix(idx_p,:) = fn_jump_ix_1variable(tr_alpha,tr_beta,...
                                          Xret(idx_p,:),deltan,nDays,nObs_per_day);
  end
end

function Xix = fn_jump_ix_1variable(tr_alpha,tr_beta,Xret,deltan,nDays,nobs)
trunc_const = tr_alpha.*deltan^(tr_beta);

if nobs<=78  % This option pools 21 consecutive trading days of intraday data 
% to detect and identify jumps in the factor or asset return processes.
    nobs = round(nobs * 21);
    nDays = round(nDays/21);
    XretMat     = reshape(Xret,nobs,nDays);
    var1         =   (sum(XretMat(1:end,:).^2)*252/21);
    var2         =   sum(XretMat(1:end,:).^2.*(abs(XretMat(1:end,:))<trunc_const*sqrt(var1)))*252/21;
    var2         =   reshape(kron(ones(nobs,1),var2),nobs*nDays,1); 
    Xix          =   abs(Xret)<trunc_const*sqrt(var2)';

else
    XretMat     = reshape(Xret,nobs,nDays);
    var1         =   (sum(XretMat(1:end,:).^2)*252);
    var2         =   sum(XretMat(1:end,:).^2.*(abs(XretMat(1:end,:))<trunc_const*sqrt(var1)))*252;
    var2         =   reshape(kron(ones(nobs,1),var2),nobs*nDays,1); 
    Xix          =   abs(Xret)<trunc_const*sqrt(var2)';

end